﻿<%@ page language="java" pageEncoding="UTF-8" %>
<%@ taglib uri="/struts-tags" prefix="s" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<%@include file="../../common/include_list_head.jsp" %>

<script type="text/javascript">
$(function () {
    //菜单按层次向后两个空格
    $("td[id^='td_']").css("text-indent",function(){
        return (($(this).attr("id").length / 3 - 3)*20)+"px";
    });
    //初始化选中 已选中的菜单
    $.each($("#menues",parent.document).val().split(","),function(i,menuid){
        $("#menu_" + menuid).attr("checked", "checked");
    });

    //查看状态保存按钮隐藏 输入框只读等
    doReadOnly();
});
//更新菜单信息
function tochangeMenu(obj) {
    if (obj.checked) { //菜单被选中时

        //菜单选中时其上级菜单默认选中
        var len_3 = obj.value.length / 3;
        for (var i = 2; i < len_3; i++) {
            var str = obj.value.substr(0, i * 3);
            if (!$("#menu_" + str).attr("checked")) { //上级菜单未选中时
                $("#menu_" + str).attr("checked", "checked");
                var menues = window.parent.document.getElementById("menues").value;
                if (menues == null || menues == '') {
                    window.parent.document.getElementById("menues").value = $("#menu_" + str).val();
                } else {
                    window.parent.document.getElementById("menues").value += "," + $("#menu_" + str).val();
                }
            }
        }
        //菜单选中时其下级菜单默认选中
        $("input[id^='menu_" + obj.value + "']").each(function (i) {
            if (!this.checked) { //上级菜单未选中时
                $(this).attr("checked", "checked");
                var menues = window.parent.document.getElementById("menues").value;
                if (menues == null || menues == '') {
                    window.parent.document.getElementById("menues").value = $(this).val();
                } else {
                    window.parent.document.getElementById("menues").value += "," + $(this).val();
                }
            }
        });
        //处理本级菜单
        var menues = window.parent.document.getElementById("menues").value;
        if (menues == null || menues == '') {
            window.parent.document.getElementById("menues").value = obj.value;
        } else {
            window.parent.document.getElementById("menues").value += "," + obj.value;
        }
    } else { //菜单取消选中时
        //下级菜单取消选中
        $("input[id^='menu_" + obj.value + "']").attr("checked", "");
        //更新菜单信息
        var menues = window.parent.document.getElementById("menues").value;
        var menue = menues.split(",");
        var curr_menues = "";
        for (var i = 0; i < menue.length; i++) {
            if (menue[i].indexOf(obj.value) != 0) {
                curr_menues += menue[i] + ",";
            }
        }
        if (curr_menues.lastIndexOf(",") == curr_menues.length - 1) {
            curr_menues = curr_menues.substr(0, curr_menues.length - 1);
        }
        window.parent.document.getElementById("menues").value = curr_menues;
    }
}
function changeAll(obj) {
    if (!obj.checked) {
        $("input[name^='selectNode']").each(function (i) { //二级菜单取消选中时,下级菜单全部取消选中
            if (this.checked) { //该菜单的按钮已选中
                $(this).attr("checked", ""); //选中菜单下的按钮后默认选中该菜单
            }
        });

        //更新菜单信息
        var menues = window.parent.document.getElementById("menues").value;

        var menue = menues.split(",");
        var curr_menues = "";
        for (var i = 0; i < menue.length; i++) {
            if (menue[i].indexOf(obj.value) != 0) {
                curr_menues += menue[i] + ",";
            }
        }

        if (curr_menues.lastIndexOf(",") == curr_menues.length - 1) {
            curr_menues = curr_menues.substr(0, curr_menues.length - 1);
        }
        window.parent.document.getElementById("menues").value = "";
//                window.parent.document.getElementById("menues").value = curr_menues;
    } else { //选中二级菜单时,默认其下级菜单全部选中
        var menues = window.parent.document.getElementById("menues").value;

        if (menues == null || menues == '') {
            window.parent.document.getElementById("menues").value = obj.value;
        } else {
            window.parent.document.getElementById("menues").value += "," + obj.value;
        }
        $("input[name='selectNodeMenu']").each(function (i) { //二级菜单取消选中时,下级菜单全部取消选中
            $(this).attr("checked", "checked"); //选中菜单下的按钮后默认选中该菜单
            menues = window.parent.document.getElementById("menues").value;
            if (menues == null || menues == '') {
                window.parent.document.getElementById("menues").value = this.value;
            } else {
                window.parent.document.getElementById("menues").value += "," + this.value;
            }
        });
    }
}

/**
 * 查询事件
 */
function doQuery(){
    var menuname = $("#menuname").val();
    if(menuname == ''){
        alert("资源名称不能为空！");
        return false;
    }
    $(".addbground").removeClass("addbground");
    $(".tableStyle tr:gt(1) td:contains('"+menuname+"')").addClass("addbground");
}
</script>
<style type="text/css">
.addbground {
    color: orangered;
}
</style>
</head>

<body>
<div id="scrollContent">
    <s:if test="actionErrors.size()>0 || actionMessages.size()>0 || fieldErrors.size()>0">
        <div id="SystemErrorMessage">
            <s:actionerror/>
            <s:actionmessage/>
            <s:fielderror/>
        </div>
    </s:if>


    <div class="box_tool_mid padding_right5" style="margin-left:5px">
        <div class="center">
            <div class="left">
                <div class="right">
                    <div class="padding_top8 padding_left10">
                        <table>
                            <tr>
                                <td>&nbsp;</td>
                                <td align="center" nowrap="nowrap" class="">
                                    &nbsp;<b>资源名称：</b>
                                    <s:textfield name="menuname" id="menuname" maxlength="50" size="10"/>
                                </td>
                                <td>
                                    <button onclick="doQuery()"><span class="icon_find">查询</span></button>
                                </td>
                            </tr>
                        </table>
                    </div>
                </div>
            </div>
        </div>
    </div>

    <table class="tableStyle" headFixMode="true" id="tab">
        <tr>
            <td align="left" colspan="5">
                <label for="menu_${upmenuid}" style="cursor: pointer;color: #0000ff">
                    <s:checkbox id="menu_%{upmenuid}" name="selectNode" fieldValue="%{upmenuid}" onclick="changeAll(this)"/>
                    <label for="menu_<s:property value="upmenuid"/>"><s:property value="menuname"/></label>
                    <s:hidden name="upmenuid"/><s:hidden name="roleid"/>全选 系统：<s:property value="appname"/>
                </label>
            </td>
        </tr>

        <tr>
            <th align="center" width="20%">功能点</th>
            <th align="center" width="10%">资源状态</th>
            <th align="center" width="10%">资源类型</th>
            <th align="center" width="10%">编号</th>
            <th align="center" width="35%">资源路径</th>
        </tr>
        <s:iterator value="resultData" id="lm" status="i">
            <tr>
                <td width="180" id="td_<s:property value='menuid'/>" nowrap="nowrap">
                    <s:checkbox id="menu_%{menuid}" name="selectNodeMenu" fieldValue="%{menuid}"
                                onclick="tochangeMenu(this)"/>
                    <label for="menu_<s:property value="%{menuid}" />"><s:property value="menuname"/>
                        <span id="span_<s:property value='%{#i.index}'/>"></span></label>
                </td>
                <td align="center">
                    <s:if test="state==0">禁用</s:if>
                    <s:else>可用</s:else>
                </td>
                <td align="center">
                    <s:property value="srctype"/></td>
                <td align="center" style="text-align: left;text-indent: 5px;">
                    <s:property value="bizcode"/></td>
                <td align="center" style="text-align: left;">
                    <s:property value="menupath"/>
                </td>
            </tr>
        </s:iterator>
    </table>
</div>
</body>
</html>
